package com.solexnlp.example.simplesemantic;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.solexnlp.simplesemantic.SimpleSemantic;
import com.solexnlp.simplesemantic.data.AnalysisResult;
import com.solexnlp.simplesemantic.data.SimpleSemanticConfiguration;

public class MainActivity extends AppCompatActivity {

    private final String TAG = "SimpleSemanticExample";

    private void example(String sentence) {
        AnalysisResult result = SimpleSemantic.getPredictor().analysis(sentence);
        if (result.getExecCode() == 0) {
            if (result.getClsIndex() == SimpleSemantic.A000) {
                // 匹配出水指令
                int arg1 = result.getSpecialInt()[0];   // 获取参数第一个数字
                Log.i(TAG, "指令序号: " + result.getClsIndex() +", 出水: " + arg1);
            } else if (result.getClsIndex() == SimpleSemantic.A001) {
                // 匹配水温调节指令
                int arg1 = result.getSpecialInt()[0];   // 获取参数中第一个数字
                Log.i(TAG, "指令序号: " + result.getClsIndex() +", 调水温: " + arg1);
            } else if (result.getClsIndex() == -1){
                // 未匹配到指令
                Log.i(TAG, "未匹配到指令");
            } else {
                // 匹配其他无参指令
                Log.i(TAG, "指令序号: " + result.getClsIndex());
            }
        } else {
            Log.e(TAG, "SDK存在错误: " + result.getExecCode());
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 初始化一个参数
        SimpleSemanticConfiguration configuration = new SimpleSemanticConfiguration();
        // 阈值默认是0.7, 根据场景需求适当增减
        configuration.setThreshold(0.7f);
        // 初始化全局的参数, 懒加载模式,
        SimpleSemantic.getPredictor().init(this, configuration);

        // 执行example函数
        String cmd1 = "帮我出50毫升的水";
        example(cmd1);
    }
}